<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 4000px;
        }

        a {
            position: fixed;
            bottom: 0;
            right: 0;
        }
    </style>
</head>

<body>

    <a>返回顶部</a>

    <script>

        // console.log(document.documentElement.scrollTop)

        var oA = document.querySelector('a');
        var flag = true;
        oA.onclick = function () {
            if (flag) {
                flag = false;
                var t = setInterval(function () {
                    document.documentElement.scrollTop -= 100;
                    if (document.documentElement.scrollTop <= 0) {
                        clearInterval(t);
                        flag = true;
                    }
                }, 10)
            }

        }


    </script>

</body>

</html>